package org.goat.caprabank.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ErrorDialog extends Composite {
	interface ErrorDialogUiBinder extends UiBinder<Widget, ErrorDialog> {
	}
	private static ErrorDialogUiBinder uiBinder = GWT.create(ErrorDialogUiBinder.class);

	public ErrorDialog() {
		uiBinder.createAndBindUi(this);
	}

	@UiField
	DialogBox errorDialogBox;

	@UiField
	Label messageLabel;

	public void showMessage(String message) {
		messageLabel.setText(message);
		errorDialogBox.center();
	}

	@UiHandler("closeButton")
	void onClickClose(ClickEvent e) {
		errorDialogBox.hide();
	}

	@UiHandler("closeButton")
	public void onKeyPressDialog(KeyPressEvent event) {
		if (event.getCharCode() == KeyCodes.KEY_ESCAPE) {
			errorDialogBox.hide();
		}
	}
}
